<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Search extends CI_Controller {
            public function __construct(){
                        parent::__construct();
                      
                }

  public function index()
  {
    
    $data=array();
    load($this->db,$this->session,$this->load,"search","index",$data);
  }



  public function del(){
            
    $id = intval($_REQUEST['id']);
    $tmp=0; 

   }


   public function get_score(){
    $empid=$this->input->get("empid");
    $starttime=@strtotime($this->input->get("starttime"));
    $endtime=@strtotime($this->input->get("endtime"));
    $sql="select sum(product_num) as product_num,product_id,sum(total) as total ,score, time from order_to_product where empid=$empid ";
    if(!empty($starttime)){
         $sql=$sql." and time >$starttime ";
    }
    if(!empty($endtime)){
         $sql=$sql." and time <$endtime ";
    }
    $sql=$sql." group by product_id";
    $query=$this->db->query($sql);
    $arr=$query->result_array();
    foreach ($arr as $key => $value) {
      foreach ($value as $key2 => $value) {
       if($key2=="product_id"){
        $sql="select name from point where id=$value";
        $query=$this->db->query($sql);
        $row=$query->row();
        $arr[$key]['product_name']=$row->name;
       }
       if($key2=="time"){
        $arr[$key]['time']=@date("Y-m-d H:i:s",$value);
       }
      }
    }
    $str=json_encode($arr);
    echo $str;

   }



         public function get_emp(){//根据用户ID获取员工列表
          $id=$this->input->get('id');
          $departstr=depart_tree_result($this->db,$this->session->userdata('depart'));
          if(!empty($id))
            {$sql="select * from employee where category=$id and depart in ($departstr) and del=0";}
          else
            {$sql="select * from employee where depart in ($departstr) and del=0";}

          $query=$this->db->query($sql);
          $arr=$query->result_array();
           foreach ($arr as $key => $value) {
              foreach ($value as $key2 => $value) {
                if($key2=="depart"){
                $sql="select name from depart where id=$value";
                $query=$this->db->query($sql);
                $row=$query->row();
                $arr[$key]['departname']=$row->name;
                 }
              }
            }

          $str=json_encode($arr);
          echo $str;
         }


          public function get_emp_category(){
          $result=read_emp_category($this->db,-1);
          $str=json_encode($result);
          echo $str;
         }


          public function get_emp_search(){//获取员工搜索
          $key=$this->input->get("key");
           $departstr=depart_tree_result($this->db,$this->session->userdata('depart'));
          $sql="select * from employee where name like '%$key%' and depart in ($departstr) and del=0 ";
      
          $query=$this->db->query($sql);
          $arr=$query->result_array();
          $str=json_encode($arr);
          echo $str;
         }



}
